define(['jquery'],function($){
    class Header{
        constructor(){
              this.loadHTML().then(()=>{
                  this.search()
                  this.calcCartTotal()
              })
              
        }
        loadHTML(){
            return new Promise( resolve => {
                $('header').load('/html/modules/header.html',()=>{
                    resolve()
                })
            })
           
        }
        search(){
            $('#keyword').on('keyup',function(){
               //向接口发送请求，接收数据，显示下拉菜单;注意事件绑定是否绑定上，search不能在同步里掉
               console.log($(this).val())
               //完成百度jsonp功能
            })
        }
        calcCartTotal(){
            //计算购物车总数
            let count = 0
            let cart = localStorage.getItem('cart')
            if(cart){
                cart = JSON.parse(cart)
                //存储的是购物车的总数
                count = cart.reduce((total,shop)=> total + shop.count,0)
            }
            $('.add-goods-num').html(count)
            $('#cart-num').html(count)
            $('#add-num1').html(count)

        }
    }
   return  new Header()
})
